package cn.tongji.edu.tjmobile;

import android.app.Activity;
import android.app.Instrumentation;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.Calendar;
import java.util.TimeZone;

public class ReadyReserveActivity extends Activity {

    private String startCampus;
    private String endCampus;
    private String time;
    private String busId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ready_reserve);

        Intent intent = getIntent();
        startCampus = intent.getStringExtra("start");
        endCampus = intent.getStringExtra("end");
        time = intent.getStringExtra("time");
        busId = intent.getStringExtra("busId");

        TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
        Calendar cal = Calendar.getInstance();
        TimeZone timeZone = cal.getTimeZone();
        cal.add(Calendar.DAY_OF_MONTH, 1);
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int day = cal.get(Calendar.DATE);
        int weekOfDay = cal.get(Calendar.DAY_OF_WEEK);
        String weekOfDayString = "";
        switch (weekOfDay) {
            case 1:
                weekOfDayString = "日";
                break;
            case 2:
                weekOfDayString = "一";
                break;
            case 3:
                weekOfDayString = "二";
                break;
            case 4:
                weekOfDayString = "三";
                break;
            case 5:
                weekOfDayString = "四";
                break;
            case 6:
                weekOfDayString = "五";
                break;
            case 7:
                weekOfDayString = "六";
                break;
        }
        String currentDate = year + "年" + month + "月" + day + "日  " + "星期" + weekOfDayString + "      " + time;

        TextView startCampusTextView = (TextView) findViewById(R.id.start_campus_textview);
        startCampusTextView.setText(startCampus);
        TextView endCampusTextView = (TextView) findViewById(R.id.end_campus_textview);
        endCampusTextView.setText(endCampus);
        TextView reserveTimeTextView = (TextView) findViewById(R.id.reserve_time_textview);
        reserveTimeTextView.setText(currentDate);

        TextView startReserveView = (TextView) findViewById(R.id.start_reserve_view);
        startReserveView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        LinearLayout ticketLayout = (LinearLayout) findViewById(R.id.ticket_layout);
        ticketLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("start", startCampus);
                intent.putExtra("end", endCampus);
                intent.putExtra("time", time);
                intent.putExtra("busId", busId);
                intent.setClass(ReadyReserveActivity.this, QRCodeReserveCancelActivity.class);
                startActivity(intent);
            }
        });

        ImageView icBackView = (ImageView) findViewById(R.id.image_ic_back);
        icBackView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new Thread () {
                    public void run () {
                        try {
                            Instrumentation inst = new Instrumentation();
                            inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
                        } catch(Exception e) {
                            e.printStackTrace();
                        }
                    }
                }.start();
            }
        });
    }
}
